﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class PurposeSystem : MonoBehaviour
{
    public Purpose nowPurpose { get; private set; }
    public abstract List<Purpose> purposeList { get; }
    public int loopNumber => purposeList.Count;

    [SerializeField] public EnemyView systemEnemyView;
    [SerializeField] public PurposeView purposeView;

    void Start()
    {
        foreach (var purpose in purposeList)
        {
            purpose.enemyView = systemEnemyView; // 统一赋值
        }
        SetPurpose(purposeList[0]);
    }

    public void SetPurpose(Purpose newPurpose)
    {
        nowPurpose = newPurpose;
        if (purposeView != null)
            purposeView.UpdatePurpose(nowPurpose.Text);
    }

    public void SetNextPurpose()
    {
        int p = (Info.Instance.turnNumber % loopNumber);
        nowPurpose._nextPurpose = purposeList[p];
    }

    // 新增一个公开方法用于外部驱动执行当前意图
    public IEnumerator PerformCurrentPurpose()
    {
        yield return nowPurpose.PurposePerformer();
        SetNextPurpose();
        SetPurpose(nowPurpose._nextPurpose);
    }
}
